package com.whu.components;

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.net.MalformedURLException;
import java.net.URL;

@Configuration
public class ImageMatchXmlRpcClient {
    @Value("${image-match.server.address}")
    private String imageMatchServerAddress;
    @Bean
    public XmlRpcClient xmlRpcClient() throws MalformedURLException {
        XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
        clientConfig.setServerURL(new URL(imageMatchServerAddress));
        clientConfig.setEnabledForExceptions(true);
        clientConfig.setEnabledForExtensions(true);
        clientConfig.setConnectionTimeout(100*1000);
        clientConfig.setReplyTimeout(100*1000);
        XmlRpcClient client = new XmlRpcClient();
        client.setTransportFactory(new XmlRpcCommonsTransportFactory(client));
        client.setConfig(clientConfig);
        return client;

    }
}
